﻿/************************************************************************************
 *      Copyright (C) 2008 greenwx.com,All Rights Reserved						    *
 *      File:																		*
 *				BaseConfigs.cs                                             			*
 *      Description:																*
 *				 基本设置类          											    *
 *      Author:																		*
 *				yuh 														        *
 *				yuh@greenwx.com 													*
 *				http://www.cnkker.com												*
 *      Finish DateTime:															*
 *				2008年11月6日       												*
 *      History:																	*
 ***********************************************************************************/
using System;
using System.Collections.Generic;
using System.Text;

namespace Yu.Cms.Config
{
    /// <summary>
    /// 基本设置类
    /// </summary>
    public class BaseConfigs
    {

        private static object lockHelper = new object();

        private static System.Timers.Timer baseConfigTimer = new System.Timers.Timer(15000);

        private static BaseConfigInfo m_configinfo;

        /// <summary>
        /// 静态构造函数初始化相应实例和定时器
        /// </summary>
        static BaseConfigs()
        {
            m_configinfo = BaseConfigFileManager.LoadConfig();
            baseConfigTimer.AutoReset = true;
            baseConfigTimer.Enabled = true;
            baseConfigTimer.Elapsed += new System.Timers.ElapsedEventHandler(Timer_Elapsed);
            baseConfigTimer.Start();
        }

        private static void Timer_Elapsed(object sender, System.Timers.ElapsedEventArgs e)
        {
            ResetConfig();
        }


        /// <summary>
        /// 重设配置类实例
        /// </summary>
        public static void ResetConfig()
        {
            m_configinfo = BaseConfigFileManager.LoadRealConfig();
        }

        public static BaseConfigInfo GetBaseConfig()
        {
            return m_configinfo;
        }

        /// <summary>
        /// 返回数据库连接串
        /// </summary>
        public static string GetDBConnectString
        {
            get
            {
                return GetBaseConfig().DbConnectstring;
            }
        }

        /// <summary>
        /// 返回DAL程序集
        /// </summary>
        public static string GetDAL
        {
            get
            {
                return GetBaseConfig().DbDAL;
            }
        }


        /// <summary>
        /// 返回系统路径
        /// </summary>
        public static string GetSitePath
        {
            get
            {
                return GetBaseConfig().SitePath;
            }
        }

        /// <summary>
        /// 返回论坛路径
        /// </summary>
        public static string GetDbType
        {
            get
            {
                return GetBaseConfig().Dbtype;
            }
        }

        /// <summary>
        /// 是否显示自定义异常
        /// </summary>
        public static bool GetCustomException
        {
            get
            {
                return GetBaseConfig().CustomException;
            }
        }
        /// <summary>
        /// 保存配置实例
        /// </summary>
        /// <param name="baseconfiginfo"></param>
        /// <returns></returns>
        public static bool SaveConfig(BaseConfigInfo baseconfiginfo)
        {
            BaseConfigFileManager acfm = new BaseConfigFileManager();
            BaseConfigFileManager.ConfigInfo = baseconfiginfo;
            return acfm.SaveConfig();
        }

    }
}
